package com.haois.mp.component.runner;

import com.google.common.base.Joiner;
import com.haois.mp.database.module.basic.util.SpringContextHolder;
import com.haois.mp.wechat.util.NetworkUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * 项目启动提示
 *
 * @author sawyerlsy
 * @date 2019-08-06
 * @since
 */
@Component
@Order(value = 10)
public class AppStartTipsRunner implements CommandLineRunner {

    @Value("${spring.application.name}")
    private String applicationName;
    @Value("${server.port}")
    private String serverPort;
    @Value("${server.servlet.context-path}")
    private String contextPath;


    private Logger logger = LoggerFactory.getLogger(AppStartTipsRunner.class);

    @Override
    public void run(String... args) {


        //打印当前环境信息
        Environment environment = SpringContextHolder.getBean(Environment.class);
        final String activeProfiles = Joiner.on(",").join(environment.getActiveProfiles());

        logger.info("{} has been started!", applicationName);

        System.out.println("*** 运行环境：" + activeProfiles);
        System.out.println("*** 系统类型：" + NetworkUtil.getOSProperties("os.name"));
        System.out.println("*** 运行路径：" + NetworkUtil.getIpAddress() + ":" + serverPort + contextPath);


        System.out.println();
        System.out.println(">>>>>>>>>>>>>>>项目 " + applicationName + " 启动成功<<<<<<<<<<<<<");

    }
}
